<!DOCTYPE html>
<html lang="en"  xmlns:th="http://www.thymeleaf.org">
	<head>
		<meta charset="utf-8">
	 <meta http-equiv="expires" content="0">
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
		<title></title>
		<link rel="stylesheet" type="text/css" th:href="@{/plugin/layui/css/layui.css}" />
		<link rel="stylesheet" th:href="@{/plugin/font-awesome/css/font-awesome.min.css}" media="all" />
		<link rel="stylesheet" th:href="@{/src/lvdong/origin/css/app.css}" media="all" />
		<link rel="stylesheet" th:href="@{/src/lvdong/origin/css/themes/default.css}" media="all" id="skin" kit-skin />
		<script th:src="@{/plugin/layui/layui.js}" type="text/javascript" charset="utf-8"></script>
  		<script th:src="@{/plugin/jquery/jquery-3.4.1.js}" charset="utf-8"></script>
		<script type="text/javascript">
		function child(data){
			var data=data;
			var form=layui.form;
			form.val("test", { //formTest 即 class="layui-form" 所在元素属性 lay-filter="" 对应的值
				   "ID":data[0].power_id
				  ,"powerName": data[0].power_name // "name": "value"
				  ,"description": data[0].description // "name": "value"
				});
	}
		</script>
	</head>
	<body>
			<form class="layui-form" action="" lay-filter="test">
  <div class="layui-form-item">
    <label class="layui-form-label">ID</label>
    <div class="layui-input-block">
      <input type="text" id="ID" name="ID" required  lay-verify="required" placeholder="ID" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">权限</label>
    <div class="layui-input-block">
      <input type="text" id="add-power" name="powerName" required  lay-verify="required" placeholder="login登录页面账号" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">描述</label>
    <div class="layui-input-block">
      <input type="text" id="add-description" name="description" required  lay-verify="required" placeholder="login登录页面账号" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn" lay-submit lay-filter="formDemo">提交编辑</button>
<!--       <button type="reset" class="layui-btn layui-btn-primary">重置</button> -->
    </div>
  </div>
</form>
 
<script>
//Demo
layui.use('form', function(){
  var form = layui.form;
  
  //监听提交
  form.on('submit(formDemo)', function(data){
            $.ajax({
              url:"/powerMg/updateOne",
              type:"POST",
              data:{
            	  power_id:$("#ID").val(),
            	  power_name:$("#add-power").val(),
            	  description:$("#add-description").val(),
              },
              dataType:'json',
		       async: false,
              success:function(data) {
                if (data.code == 200) {
                  layer.close(layer.index);
                  layer.msg(data.msg);
                  table.reload('test');
                } else {
                  layer.msg(data.msg);
                }
              },
              error: function() {
                console.log("ajax error");
              }
            });
  });
});
</script>
	</body>
</html>
